package com.pl.myshop.provider.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.pl.myshop.provider.api.UesrService;
import com.pl.myshop.provider.domain.UmsAdmin;
import com.pl.myshop.provider.mapper.UmsAdminMapper;
import com.pl.myshop.provider.service.fallback.UmsServiceFallback;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;

/**
 * @Auther: pl
 * @Date: 2020/3/26 09:26
 * @Description:
 */
@Service(version = "1.0.0")
public class UserServiceImp implements UesrService {

    private static final Logger logger = LoggerFactory.getLogger(UserServiceImp.class);

    @Resource
    private UmsAdminMapper umsAdminMapper;

    @Override
    @SentinelResource(value = "getByUsername",fallback = "getByUsernameFallback",fallbackClass = UmsServiceFallback.class)
    public UmsAdmin getUserByUserName(String userName) {
      /*  if ("admin".equals(userName)){
            throw new IllegalArgumentException("熔断");
        }*/

        Example example = new Example(UmsAdmin.class);
        example.createCriteria().andEqualTo("username",userName);
        logger.info("sentinel管理的服务");
        return umsAdminMapper.selectOneByExample(example);
    }
}